package com.tjec.project.msg.api;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.xml.rpc.holders.LongHolder;
import javax.xml.rpc.holders.StringHolder;
import com.tjec.project.msg.factory.DataObjectFactory;
import com.tjec.project.msg.mobset.bean.DataObjectBean;
import com.tjec.project.msg.mobset.bean.msmResultBean;
import com.tjec.project.msg.tempuri.MobileListGroup;
import com.tjec.project.msg.tempuri.MobsetApiSoap;
import com.tjec.project.msg.tempuri.holders.ArrayOfSmsIDListHolder;
import com.tjec.project.msg.util.MD5;

/**
 * @author villwang
 * @date 2020/07/08
 **/
public class SendMsg {

    private static long corpID;
    private static String loginName;
    private static String password;
    private static URL url;
    private static String timeStamp = "1105203910";
    private static String addNum;
    private static String timer = "2012-11-05 20:39:10";
    private static long longSms = 0L;
    private static MobileListGroup[] mobileList;
    private static StringHolder errMsg;
    private static ArrayOfSmsIDListHolder smsIDList;
    private static LongHolder count;

    public SendMsg() {
    }

    public static msmResultBean SendMsg(ArrayList<String> mobiles, String content) {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmmss");
        timeStamp = dateFormat.format(now);
        System.out.println(timeStamp);
        errMsg = new StringHolder();
        smsIDList = new ArrayOfSmsIDListHolder();
        count = new LongHolder();
        msmResultBean msmBean = new msmResultBean();
        DataObjectBean bean = DataObjectFactory.getInstance();
        corpID = new Long(bean.getCordId());
        loginName = bean.getUserName();
        password = bean.getPasswd();

        try {
            url = new URL(bean.getServerIP());
        } catch (Exception var11) {
            var11.printStackTrace();
        }

        MobsetApiSoap mobset = DataObjectFactory.getMobsetApi(url);
        mobileList = new MobileListGroup[mobiles.size()];

        for(int i = 0; i < mobileList.length; ++i) {
            mobileList[i] = new MobileListGroup();
            mobileList[i].setMobile(mobiles.get(i));
        }

        MD5 md5 = new MD5();
        password = md5.getMD5ofStr(corpID + password + timeStamp);
        System.out.println("----------"+password);
        try {
            mobset.sms_Send(corpID, loginName, password, timeStamp, addNum, timer, longSms, mobileList, content, count, errMsg, smsIDList);
            msmBean.setErrMsg(errMsg);
            msmBean.setMobileList(mobileList);
            msmBean.setSmsIDList(smsIDList);
        } catch (RemoteException var10) {
            var10.printStackTrace();
        }

        return msmBean;
    }
}
